package com.yupi.springbootinit.model.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

@Getter
@RequiredArgsConstructor
public enum ReviewStatusEnum {
    PENDING(0, "待审核"),
    APPROVED(1, "通过"),
    REJECTED(2, "拒绝");

    private final Integer code;
    private final String description;


    /**
     * 根据审核状态码获取枚举对象
     *
     * @param code 状态码（0/1/2）
     * @return 对应的枚举对象，若不存在返回 null
     */
    public static ReviewStatusEnum fromCode(Integer code) {
        if (code == null) return null;
        return Arrays.stream(values())
                .filter(status -> status.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }
}